<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="text" class="user">
    <br> <br>
    <input type="password" class="pwd"> 
    <br><br>
    <button>注册</button>


    <script src="../js/tools.js"></script>

    <script>

        const oBtn = getEle('button') ;
        const oUser = getEle('.user') ;
        const oPwd = getEle('.pwd') ;

        oBtn.addEventListener('click' , function() {
            // 获取用户名和密码
            const uname = oUser.value ;
            const upwd = oPwd.value ;

            //判断
            if(uname && upwd) {
                const res = getCookie('YYDS_' + uname) ;
                if(res) {
                    alert('用户名已被注册');
                } else {
                    alert('注册成功');
                    // 把用户名存入cookie 
                    setCookie('YYDS_' + uname , upwd) ;
                    location.href = './04login.html' ;
                }
            }
        })

    </script>
    
</body>
</html>